import React from 'react'
import {useLocalStorage} from '@rehooks/local-storage'

const Local = () => {
    //使用本地存储的插件
    const [user, setUser,delUser] = useLocalStorage('user',{})//等价于声明一个状态，user对象，值为空
    const [num, setNum,delNum] = useLocalStorage('num',100)
    return (
        <div>
            <div>
                <h2>{user.name}</h2>
                <button onClick={()=>setUser({'name':'zhangsan'})}>设置user</button>
                <button onClick={delUser}>删除用户</button>
            </div>
            <div>
                <h2>{num.num}</h2>
                <button onClick={()=>setNum({num:'99'})}>设置Num</button>
                <button onClick={delNum}>删除数字</button>
            </div>
        </div>
    )
}

export default Local